/**
 * 深度克隆对象
 * @param obj
 */
export function deepClone<T>(obj: T): T {
    if (obj === null || typeof obj !== 'object') {
        return obj;
    }

    // 处理特殊对象类型
    if (obj instanceof Date) return new Date(obj) as any;
    if (obj instanceof RegExp) return new RegExp(obj) as any;

    const clone: any = Array.isArray(obj) ? [] : {};

    for (const key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
            clone[key] = deepClone(obj[key]);
        }
    }

    return clone;
}


/**
 * 处理时间范围查询
 * @param dateRange 选择的时间范围
 * @param params 查询参数
 * @returns
 */
export function handleDateRangeChange(dateRange: any, params: any) {
    if (typeof params !== 'object' || params === null || Array.isArray(params)) {
        params = {};
    }
    if (Array.isArray(dateRange) && dateRange.length === 2) {
        params.beginTime = dateRange[0];
        params.endTime = dateRange[1];
        return
    }

    params.beginTime = '';
    params.endTime = '';
}

/**
 * 获取图片地址,渲染图片
 * @param filename
 */
export const getImgUrl = (filename: string): string => {
    return `http://localhost:8018/file/image?imageName=${encodeURIComponent(filename)}`;
}

